package org.example.springioc.controller;

import org.example.springioc.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

@Controller
@Component
public class HelloController {
    //1.属性注入
    @Autowired
    public UserService userService;
//
//    public HelloController(){
//
//    }
//
    //2.构造方法注入
    @Autowired
    public HelloController(UserService userService) {
        this.userService = userService;
    }

    //3.Setter方法注入  默认不会执行 需要加@Autowired
    @Autowired
    public void setUserService(UserService userService){
        this.userService = userService;
    }

    public void sayHi(){
        userService.doService();
        System.out.println("hi,HelloController...");
    }
}
